Repository navigation
Combine repeated Accept-Encoding header lines when negotiating compression - #1090
Closed
BahaaMattar wants to merge 1 commit into
Closed
BahaaMattar wants to merge 1 commit into
BahaaMattar wants to merge 1 commit into
Conversation
…ssion Handlers read only the first value of Accept-Encoding, Connect-Accept-Encoding and Grpc-Accept-Encoding. A client that sent the encodings it accepts on separate header lines, such as "br" and then "gzip", got an uncompressed response even though the handler supports gzip. Several header lines with the same name mean the same as one comma-separated line (RFC 9110 Section 5.3), so join them before choosing the response encoding. Fixes connectrpc#1089 Signed-off-by: Bahaa Mattar <bahaa.kmattar@gmail.com>
Member
|
Thanks for the contribution! There are open questions on #1089 that may affect what the right fix is, so I'd like to settle those on the issue first. Closing for now. We can reopen once that's decided. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1089
Handlers chose the response compression from only the first value of
Accept-Encoding (unary Connect), Connect-Accept-Encoding (streaming Connect)
and Grpc-Accept-Encoding (gRPC and gRPC-Web). If a client lists the encodings
it accepts on separate header lines, for example
Accept-Encoding: brandthen
Accept-Encoding: gzip, the handler only sawbr, found no match andsent the response uncompressed even though it supports gzip. RFC 9110 section
5.3 says several lines with the same name are equivalent to one
comma-separated line.
This adds
getHeaderCanonicalJoined, which joins the values with a comma, anduses it for the three accept-encoding lookups. A single header line is
returned as-is, so the common case is unchanged. The request's own
Content-Encoding is still read as a single value.
Tests:
TestHandlerRepeatedAcceptEncodingsendsbrandgzipon two separatelines to a Connect unary, a Connect streaming and a gRPC handler and
expects gzip for each. It fails on main for all three and passes with this
change.
Test_getHeaderCanonicalJoinedcovers the helper (none, one, severalvalues, and values that already contain commas).